package com.yimi.policyservice.repository;

import com.yimi.policyservice.entity.base.system.SysUserDataPermission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface UserDataPermissionRepository extends JpaRepository<SysUserDataPermission,String> {
    @Transactional
    @Modifying
    @Query(value = "delete  from t_sys_user_data_permission  where user_id=?1 ",nativeQuery = true)
    void deleteByUserId(String id);

    @Query(value = "select  data_value  from t_sys_user_data_permission p where p.user_id=?1 and p.data_type=?2 ",nativeQuery = true)
    List<String> findUserPermissions(String userId, int type);

    @Query(value = "select  data_value  from t_sys_user_data_permission p where p.user_id=?1 and p.data_value=?2 and p.data_type=?3 ",nativeQuery = true)
    List<String> findUserPermissions(String userId,String dateValue, int type);
}
